package cn.zbzcode.hrm.feign.fallback;

import cn.zbzcode.hrm.feign.client.RedisFeignClient;
import cn.zbzcode.hrm.utils.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RedisFeignClientFallbackFactory implements FallbackFactory<RedisFeignClient> {
    @Override
    public RedisFeignClient create(Throwable throwable) {
        return new RedisFeignClient(){

            @Override
            public AjaxResult set(String key, String value) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("缓存服务不可用");
            }

            @Override
            public AjaxResult get(String key) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("缓存服务不可用");
            }

            @Override
            public AjaxResult setex(String key, int seconds, String value) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false).setMessage("缓存服务不可用");
            }
        };
    }
}